<?php
abstract class ASkillBase {
	public $name;
	private $skill;
	private $uid;
	
	public function __construct($name) {
		$this->name = $name;
		
		$Auth = Auth::getAuth();
		$uid = $this->uid = $Auth->id;
		
		$model = new SkillModel();
		
		$this->skill = new SkillObject($name);
		
		$skillid = $model->getSkillId($name);
		$level = $model->getSkillLevel($skillid, $uid);
	}
	
	public function checkUseCondition() {
		$model = new SkillModel();
		$model->reactivateOld();
		return $model->getSkillStatus($this->skill->id, $this->uid) == '1';
	}
	
	public function checkUpgradeCondition() {
		$depen = $this->getDependancies();
		$user = new UserDataObject($this->uid);
		$exp = $user->exp;
		if ($exp < 1) return false;
		$status = true;
		
		$model = new SkillModel();
		
		foreach ($depen as $skill=>$level) {
			$skilid = $model->getSkillId($this->skill);
			$l = $model->getSkillLevel($skilid, $this->uid);
			
			if ($l < $level) $status = false;
		}
		
		return $status; // TODO
	}
	
	public function activate() {
		if ($this->checkUseCondition()) {
			$model = new SkillModel();
			$model->deactivate($this->skill->id);
			$model->setReactivate($this->skill->id, $this->uid, $this->getCooldownTime());
		}
	}
	
	public function getCurrentLevel() {
		$model = new SkillModel();
		return $model->getSkillLevel($this->skill->id, $this->uid);
	}
	
	// Modifier function
	public function getCooldownTime() { return 20; }

	public function getDependancies() { return array(); }
	public function getCooldownModifier() { return 0; }
	public function getScoreModifier() { return 0; }
}
